import { getDefaultFields } from '../utils';

// 优惠券表设计
module.exports = app => {
  const DataTypes = app.Sequelize;

  const Model = app.model.define('sms_coupon', {
    id: {
      type: DataTypes.INTEGER(11),
      allowNull: false,
      primaryKey: true,
      autoIncrement: true,
    },
    type: {
      type: DataTypes.INTEGER(1),
      allowNull: true,
      comment: '优惠卷类型；0->全场赠券；1->会员赠券；2->购物赠券；3->注册赠券',
      enum: [0, 1, 2, 3],
      defaultValue: 0,
    },
    name: {
      type: DataTypes.STRING(200),
      allowNull: true,
    },
    platform: {
      type: DataTypes.INTEGER(1),
      allowNull: true,
      comment: '使用平台：0->全部；1->小程序；2->PC',
      enum: [0, 1, 2],
      defaultValue: 0,
    },
    count: {
      type: DataTypes.INTEGER(11),
      allowNull: true,
      defaultValue: 0,
      comment: '数量'
    },
    amount: {
      type: DataTypes.INTEGER(11),
      allowNull: true,
      defaultValue: 0,
      comment: '金额'
    },
    per_limit: {
      type: DataTypes.INTEGER(11),
      allowNull: true,
      defaultValue: 0,
      comment: '每人限领张数'
    },
    min_point: {
      type: DataTypes.INTEGER(11),
      allowNull: true,
      defaultValue: 0,
      comment: '使用门槛；0表示无门槛'
    },
    coupon_start_time: {
      type: DataTypes.BIGINT,
      allowNull: true,
      comment: '开始使用时间'
    },
    coupon_end_time: {
      type: DataTypes.BIGINT,
      allowNull: true,
      comment: '结束使用时间'
    },
    use_type: {
      type: DataTypes.INTEGER(1),
      allowNull: true,
      comment: '使用类型：0->全场通用；1->指定分类；2->指定商品',
      enum: [0, 1, 2],
      defaultValue: 0,
    },
    note: {
      type: DataTypes.STRING(200),
      allowNull: true,
      comment: '备注',
      defaultValue: ''
    },
    publish_count: {
      type: DataTypes.INTEGER(11),
      allowNull: true,
      defaultValue: 0,
      comment: '发行数量'
    },
    use_count: {
      type: DataTypes.INTEGER(11),
      allowNull: true,
      defaultValue: 0,
      comment: '已使用数量'
    },
    receive_count: {
      type: DataTypes.INTEGER(11),
      allowNull: true,
      defaultValue: 0,
      comment: '领取数量'
    },
    enable_time: {
      type: DataTypes.BIGINT,
      allowNull: true,
      comment: '可以领取的日期'
    },
    code: {
      type: DataTypes.STRING(64),
      allowNull: true,
      comment: '优惠码',
      defaultValue: ''
    },
    ...getDefaultFields()
  }, {
    tableName: 'sms_coupon',
    timestamps: false,
  });

  Model.sync({ alter: true });
  Model.associate = function() {
  };

  return Model;
};
